<?php
require_once('settings.php');
$settings = new settings;
$siteDetails = $settings->getSiteDetails();
$url = (string) $siteDetails->siteUrl;

session_start();
// $session_id = '1';
// User session id
$path = "images/";

$valid_formats = array("jpg", "png", "gif", "bmp", "jpeg");
if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
	$name = $_FILES['photoimg']['name'];
	$size = $_FILES['photoimg']['size'];
	if (strlen($name)) {
		list($txt, $ext) = explode(".", $name);
		$ext = strtolower($ext);
		if (in_array($ext, $valid_formats)) {
			if ($size < (1024 * 1024 * 2))// Image size max 2 MB
			{
				$actual_image_name = time() . "." . $ext;
				$tmp = $_FILES['photoimg']['tmp_name'];
				
				
				
				include('lib/SimpleImage.php'); 
				$image = new SimpleImage(); 
				$image->load($_FILES['photoimg']['tmp_name']); 
				$image->resizeToWidth(200); 
				$image->save($path . $actual_image_name);
				
				
				
				// if (move_uploaded_file($tmp, $path . $actual_image_name)) {
				echo 	"<img src='".$url."images/" . $actual_image_name . "' class='preview'>
						 <input type='hidden' name='image' value='$actual_image_name'>";
				// } else echo "failed";
			} else
				echo "Image file size max 1 MB";
		} else
			echo "Invalid file format..";
	} else
		echo "Please select image..!";
	exit ;
} else echo 'dupa';
?>